#include "Metgine/Input/KeyboardManager.hpp"


namespace Metgine
{
namespace Input
{

void KeyboardManager::Update()
{
    for(int i = 0; i < sf::Key::Count; i++)
    {
        m_pressedKeys[i] = m_mainInput.IsKeyDown((sf::Key::Code)i);

        if (m_lastPressed == (sf::Key::Code)i && !m_pressedKeys[(int)m_lastPressed])
            m_lastReleased = m_lastPressed;

        if (m_pressedKeys[i])
            m_lastPressed = (sf::Key::Code)i;
    }
}

bool KeyboardManager::IsKeyDown(sf::Key::Code KeyCode)
{

    return m_pressedKeys[(int)KeyCode];
}

bool KeyboardManager::IsAnyKeyDown()
{
    for(int i = 0; i < sf::Key::Count; i++)
    {
        if (IsKeyDown((sf::Key::Code)i))
            return true;
    }

    return false;
}

bool KeyboardManager::IsAnyKeyReleased()
{
    for(int i = 0; i < sf::Key::Count; i++)
    {
        if (IsKeyReleased((sf::Key::Code)i))
            return true;
    }

    return false;
}

bool KeyboardManager::IsKeyUp(sf::Key::Code KeyCode)
{
    return !m_pressedKeys[(int)KeyCode];
}

bool KeyboardManager::IsKeyReleased(sf::Key::Code KeyCode)
{
    return (!m_mainInput.IsKeyDown(KeyCode) && m_pressedKeys[(int)KeyCode]);
}

void KeyboardManager::SetKey(sf::Key::Code KeyCode, bool Pressed)
{
    m_pressedKeys[(int)KeyCode] = Pressed;
}

sf::Key::Code KeyboardManager::GetLastPressed()
{
    return m_lastPressed;
}

sf::Key::Code KeyboardManager::GetLastReleased()
{
    return m_lastPressed;
}

}; // Input
}; // Metgine

